package capstoneproject.dudiachi.Controller;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class InternetConnectionDetector {

	private Context _context;

	public InternetConnectionDetector(Context context) {
		this._context = context;
	}

	/**
	 * <pre>
	 * check if the device has connection or not.
	 * インター�?ット�?�接続�?�る�?��?��?��??る�?��?��?��?��?ェック�?��?��?�。
	 * </pre>
	 * 
	 * @return
	 */
	public boolean checkInternetConnection() {
		// Create object for ConnectivityManager class which returns network
		// related info
		ConnectivityManager connectivity = (ConnectivityManager) _context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		// If connectivity object is not null
		if (connectivity != null) {
			// Get network info - WIFI internet access
			NetworkInfo infoWifi = connectivity
					.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
			// Get network info - MOBILE internet access
			NetworkInfo infoMobile = connectivity
					.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
			if (infoWifi != null) {
				// Look for whether device is currently connected to WIFI
				// network
				if (infoWifi.isConnected()) {
					return true;
				}
			}
			if (infoMobile != null) {
				if (infoMobile.isConnected()) {
					return true;
				}
			}
		}
		return false;
	}

}
